package com.winhxd.b2c.customer.service.impl.listener;

import com.winhxd.b2c.common.domain.order.vo.OrderRebateRecordVO;
import com.winhxd.b2c.common.mq.event.EventMessageListener;
import com.winhxd.b2c.common.mq.event.EventTypeHandler;
import com.winhxd.b2c.common.util.JsonUtil;
import com.winhxd.b2c.customer.service.CustomerRevenueService;
import com.winhxd.b2c.customer.service.impl.CustomerRevenueServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author caiyulong
 */
@Profile({"test","prod"})
@Component
public class OrderOperationListener {

    private static final Logger logger = LoggerFactory.getLogger(OrderOperationListener.class);

    @Autowired
    private CustomerRevenueService customerRevenueService;

    /**
     * 订单转正监听
     */
    @EventMessageListener(value = EventTypeHandler.OUTLET_EVENT_CUSTOMER_ORDER_FINISHED_CALCULATE_REVENUE,concurrency = "2-4")
    public void orderClosed(String key, OrderRebateRecordVO orderRebateRecordVO){
        try {
            customerRevenueService.orderClosedCalculateRevenue(orderRebateRecordVO);
        } catch (Exception e){
            logger.error("#收益计算# - 计算异常 orderNo=" + orderRebateRecordVO.getOrderNo() + " message={}" , e);
            throw e;
        }
    }
}
